﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using Hjp.FrameWork.Common;
using Wjtour.BLL;

namespace Wjtour.Ajax
{
    /// <summary>
    /// Summary description for login
    /// </summary>
    public class ZanHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            var type = context.Request["type"];
            var id = Utils.StrToInt(context.Request["id"], 0);

            Wjtour.BLL.article_bll _article_bll = new article_bll();
            Wjtour.BLL.sitepicture_bll _sitepicture_bll = new sitepicture_bll();

            Result r = new Result();
            if (type == "article")
            {
                Wjtour.Domain.article a = _article_bll.Load(id);
                a.zan += 1;
                bool b = _article_bll.Save(a);
                if (b)
                {
                    r.Errcode = "0";
                    r.Errmsg = "赞成功！";
                    r.Data = a.zan.ToString();
                }
            }
            else if (type == "pic")
            {
                var s = _sitepicture_bll.Load(id);
                s.zan += 1;
                bool b = _sitepicture_bll.Save(s);
                if (b)
                {
                    r.Errcode = "0";
                    r.Errmsg = "赞成功！";
                    r.Data = s.zan.ToString();
                }

            }
            else
            {
                r.Errcode = "999";
                r.Errmsg = "操作失败！";
            }
            JavaScriptSerializer serialzier = new JavaScriptSerializer();
            string output = serialzier.Serialize(r);
            context.Response.Write(output);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}